# pragma once
#include<graphics.h>
#include"player.h"
static bool running = true;
static	bool gamestart = 0;
const int buttonwidth = 192;
const int buttonheight = 75;
class Button
{
protected:
	virtual void OnClick() = 0;
public:
	Button(RECT rect, LPCTSTR path1, LPCTSTR path2, LPCTSTR path3)
	{
		region = rect;
		loadimage(&imgidle, path1);
		loadimage(&imghovered, path2);
		loadimage(&imgpushed, path3);
	}
	bool checkshubiao(int x, int y)
	{
		return x >= region.left && x <= region.right && y >= region.top && y <= region.bottom;
	}
	void possessevent(const ExMessage& msg)
	{
		switch (msg.message)
		{
		case WM_MOUSEMOVE:
			if (status == Status::Idle && checkshubiao(msg.x, msg.y))
				status = Status::Hovered;
			else if (status == Status::Hovered && !checkshubiao(msg.x, msg.y))
				status = Status::Idle;
			break;
		case WM_LBUTTONDOWN:
			if (checkshubiao(msg.x, msg.y))
				status = Status::pushed;
			break;
		case WM_LBUTTONUP:
			if (status == Status::pushed)
				OnClick();
			break;
		default:
			break;
		}

	}
	void draw()
	{
		switch (status)
		{
		case Status::Idle:
			putimage(region.left, region.top, &imgidle);
			break;
		case Status::Hovered:
			putimage(region.left, region.top, &imghovered);
			break;
		case Status::pushed:
			putimage(region.left, region.top, &imgpushed);
			break;
		}
	}
private:
	enum class Status
	{
		Idle = 0,
		Hovered,
		pushed
	};
private:
	RECT region;
	IMAGE imgidle;
	IMAGE imghovered;
	IMAGE imgpushed;
	Status status = Status::Idle;
};
class startbutton :public Button
{
public:
	startbutton(RECT rect, LPCTSTR path1, LPCTSTR path2, LPCTSTR path3)
		:Button(rect, path1, path2, path3) {};
	~startbutton() = default;
protected:
	void OnClick()
	{
		gamestart = 1;
	}
};
class finishbutton :public Button
{
public:
	finishbutton(RECT rect, LPCTSTR path1, LPCTSTR path2, LPCTSTR path3)
		:Button(rect, path1, path2, path3) {};
	~finishbutton() = default;
protected:
	void OnClick()
	{
		running = 0;
	}
};
void bulletfollow(vector<Bullet>& bullets, const Player& player)
{
	const double speed1 = 0.0045;
	const double speed2 = 0.0055;
	double jiaodu = 2 * 3.14159 / bullets.size();
	POINT Position = player.getplayer();
	double randis = 100 + 25 * sin(GetTickCount() * speed1);
	for (int i = 0; i < bullets.size(); i++)
	{
		double radian = GetTickCount() * speed2 + jiaodu * i;
		bullets[i].position.x = Position.x + player_width / 2 + int(randis * sin(radian));
		bullets[i].position.y = Position.y + player_height / 2 + int(randis * cos(radian));
	}
}